package leetcode;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * create by duanx 2022/1/4
 *@description： todo
 *@classname: Fibonacci
 *@author: duanx
 *@date: 2022/1/4 11:29
 **/
public class Fibonacci {

    private final static Logger logger = LoggerFactory.getLogger(Fibonacci.class);

    /**
     * 斐波那契列  1 1 2 3 5 8
     * @param n 位数
     * @return 第n位
     */
    public static int fibonacci(int n){
        if (n<=1){
            return n;
        }
        int [] fb = new int[n+1];
        fb[1]=1;
        for (int i=2;i<=n;i++){
            fb[i] = fb[i-1]+fb[i-2];
        }
        return fb[n];
    }

    public static void main(String[] args) {
        logger.info(String.valueOf(fibonacci(2)));
    }

}
